<?php

header("content-type:text/html;chartset=utf-8");

    //通过transactionId查询状态
    include '../common/dblib.php'; //for MySQL 
    $rows = array();
        
    if(function_exists('SQL_Query')){

        db_connect();

        $sql = "select t.extransactionid from transaction t join merchant m on  t.merchantid = m.merchantid and m.ex_merchantid = 'MDP54aa92882cd7c'";

        $result = SQL_Query($sql);

        while( $row = db_fetch_array($result)){
            $rows[] = $row[0];
        }
        db_free_result($result);
        db_disconnect();
    }
        
        
    if( $_POST){
        
        include 'request.php';
        
        $url = '192.168.33.10/gmasiatech/merchant/process.php';
        $merchantId = $_POST['merchantId'];
        $transactionId = $_POST['transactionId'];
        
        $sign = md5('magicMDP'.$merchantId.$transactionId.$amount);
        
	$xml_str ="xmlStr=<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
                <request>
					<method>reqTransactionQuery</method>
					<merchantId>$merchantId</merchantId>
                                        <transactionId>$transactionId</transactionId>
					<sign>$sign</sign>
                </request>";

        
        $res2 = sendRequest($url, $xml_str);
        
        if(strpos($res2, '001') !== false){
            $desc = '请求成功.';
        }elseif(strpos($res2, '100') !== false){
            $desc = '商户不存在.';
        }elseif(strpos($res2, '101') !== false){
            $desc = '有参数无效.';
        }elseif(strpos($res2, '102') !== false){
            $desc = 'Sign验证失败.';
        }elseif(strpos($res2, '103') !== false){
            $desc = 'TransId已存在.';
        }elseif(strpos($res2, '104') !== false){
            $desc = '单次交易金额未达要求.';
        }elseif(strpos($res2, '105') !== false){
            $desc = '总交易金额未达要求.';
        }elseif(strpos($res2, '106') !== false){
            $desc = '网络错误.';
        }elseif(strpos($res2, '107') !== false){
            $desc = '交易不存在.';
        }elseif(strpos($res2, '108') !== false){
            $desc = '银行账户不存在.';
        }
   
        $xml = simplexml_load_string($res2);

        $xml = json_decode(json_encode($xml),TRUE);
     
        echo '<h1>';
        echo '返回值：'.$xml['transaction']['status'].'_'.$desc;
        echo '</h1>';
    }


?>

<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
        tr{margin-bottom: 15px;}
        tr td:first-child{text-align: right;padding-right: 10px;font-weight: bold}
        form  input:not(.submit){height:30px;width:200px;}
        .readonly{border:1px solid #ccc;color:#888;}
        em{font-size: 14px;}
    </style>
</head>

<h5><a href="index.html">回到首页</a></h5>
<h3>Fund In.</h3>
<hr>

<form action="" method="post">
<table CellSpacing=10>
   <tr><td>merchantId:</td>         <td><input type="text" name="merchantId" class="readonly" value="MDP54aa92882cd7c" readonly > <em>真实数据：商户的mdpId</em>
   
   <tr><td>transactionId:</td>      <td>
           
                                        <select name="transactionId"> 
                                            <?php foreach($rows as $k=>$v){?>
                                            <option value="<?php echo $v?>"><?php echo $k.'.'.$v?></option>
                                            <?php }?>
                                         </select>   
                                         <em>真实数据：唯一交易ID</em>
 
   
   <tr><td>SUBMIT:</td>             <td><input type="submit" value="GO"  class="submit" >
</table>
</form>